package pl.google_wave_blog.plcensorbot;

import com.google.wave.api.AbstractRobotServlet;
import com.google.wave.api.Blip;
import com.google.wave.api.Event;
import com.google.wave.api.EventType;
import com.google.wave.api.RobotMessageBundle;

public class PLCensorBotServlet extends AbstractRobotServlet {
	BadWords bwords = new BadWords();

	@Override
	public void processEvents(RobotMessageBundle rmb) {
		bwords.getWordsList();
		for (Event e : rmb.getEvents()) {
			if (e.getType() == EventType.BLIP_SUBMITTED) {
				Blip blip = e.getBlip();
				String censoredText = bwords.censor(blip.getDocument()
						.getText());
				if (!blip.getDocument().getText().equals(censoredText))
					blip.getDocument().replace(censoredText);
			}
		}
	}
}
